package com.zzx.test.reflection;

import com.zzx.test.entity.Person;
import org.junit.Test;

/**
 * @ClassName: GetClassTest1
 * @Description: 获取Class对象测试类
 * @Author zhouzhixin
 * @Date 2021/12/6
 * @Version 1.0
 */
public class GetClassTest1 {

    @Test
    public void test1() {
        String reference = "com.zzx.test.entity.Person";
        Person person = new Person();
        try {
            ClassLoader classLoader = person.getClass().getClassLoader();

            Class<?> personClass1 = Class.forName(reference);
            Class<Person> personClass2 = Person.class;
            Class<? extends Person> personClass3 = person.getClass();
            Class<?> personClass4 = classLoader.loadClass(reference);

            System.out.println(personClass1.hashCode());
            System.out.println(personClass2.hashCode());
            System.out.println(personClass3.hashCode());
            System.out.println(personClass4.hashCode());

            System.out.println("---------------------");
            Class<Integer> integerClass1 = int.class;
            Class<Double> doubleClass1 = double.class;
            Class<Integer> integerClass2 = Integer.TYPE;
            Class<Double> doubleClass2 = Double.TYPE;
            System.out.println(integerClass1.hashCode());
            System.out.println(integerClass2.hashCode());
            System.out.println(doubleClass1.hashCode());
            System.out.println(doubleClass2.hashCode());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
